package handler

import (
	"context"
	dev "qld2devservice/proto"
	"qld2devservice/service"
)

// apiController 控制器
type handlerDevMqttController struct{}

func NewDevMqttController() dev.DevMqttServer {
	return &handlerDevMqttController{}
}

//// OutLetMakeListenTopic 设备命令
//func (that *handlerDevMqttController) DevMqttMakeListenTopic(ctx context.Context, p *dev.DevMqttMakeListenTopicRequest) (res *dev.DevMqttMakeListenTopicResponse, err error) {
//	utils.MyPrint(utils.PRINT_INFO , "DevMqttMakeListenTopic request", utils.TransProtoToJson(p))
//	defer func() {
//		utils.MyPrint(utils.PRINT_INFO , "DevMqttMakeListenTopic response", utils.TransProtoToJson(res))
//	}()
//	res = &dev.DevMqttMakeListenTopicResponse{}
//	res.Topic = service.DevMqttMakeListenDeviceTopic()
//	return res, nil
//}

// OutLetAnalyzeMqttData 设备命令
func (that *handlerDevMqttController) DevMqttAnalyzeMessage(ctx context.Context, p *dev.DevMqttAnalyzeMessageRequest) (res *dev.DevMqttAnalyzeMessageResponse, err error) {
	//utils.MyPrint(utils.PRINT_INFO , "DevMqttAnalyzeMessage request", utils.TransProtoToJson(p))
	//defer func() {
	//	utils.MyPrint(utils.PRINT_INFO , "DevMqttAnalyzeMessage response",res,err.Error())
	//}()
	res = &dev.DevMqttAnalyzeMessageResponse{}
	res.Response = make([]string, len(p.Payload))
	for i := 0; i < len(p.Payload); i++ {
		res.Response[i] = service.AnalyzeMqttListrnMessageResponse(p.Payload[i].Topic, p.Payload[i].Message)
	}
	return res, nil
}
